﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
	<link href="js-console.css" rel="stylesheet" />
	<!-- 9. Write an expression that checks for given point (x, y) 
			if it is within the circle K( (1,1), 3) and out of the 
			rectangle R(top=1, left=-1, width=6, height=2). -->
</head>
<body>
	<div id="js-console"></div>
	<script src="js-console.js"></script>
	<script>
		//Point coordinates (x, y)
		var pointX = prompt("Enter X coordinate");
		var pointY = prompt("Enter Y coordinate");

		if (!isNaN(pointX) && !isNaN(pointY)) {
			pointX *= 1; pointY *= 1;	// make them real number

			//------------------------------------------
			// Checks if the point is within the Circle
			//------------------------------------------
		
			// Circle input parameters
			// Circle with center certain point
			var circleRadius = 5;
			var circleX = 1;
			var circleY = 1;

			var newX = pointX - circleX;
			var newY = pointY - circleY;

			// result for circle
			var resultWithinCircle =
				((newX * newX) + (newY * newY)) < (circleRadius * circleRadius);

			//------------------------------------------
			// Check if outside rectangle
			//------------------------------------------

			// Rectangle input parameters
			var rectangleTop = 1;
			var rectangleLeft = -1;
			var rectangleWidht = 6;
			var rectangleHeight = 2;

			var rectangleRight = rectangleLeft + rectangleWidht;
			var rectangleBottom = rectangleTop - rectangleHeight;

			// result for rectangle
			var resultOutsideRectangle = 
				(pointX > rectangleTop || pointX < rectangleBottom ||
					pointY < rectangleLeft || pointY > rectangleRight);

			// Output to console
			jsConsole.writeLine("Point is within the circle and outside the rectangle = " + 
									(resultWithinCircle && resultOutsideRectangle));
		}
		else {
			jsConsole.writeLine("Wrong input.");
		}

	</script>
</body>
</html>
